import * as actions from '../actions/index';
// 页面初始化数据
const initialState = {
  pageSize: 10,
  tabKey: 'overview',
  branchesData: [],
  overviewData: {},
  total: 0,
  isLoading: true,
};
const defaultAction = {
  type: 'doNothing',
};
export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {
    case actions.UPDATE_DATA:
      return { ...state, ...action.data };
    case actions.SET_TAB_KEY:
      return { ...state, tabKey: action.data };
    case actions.RECEIVE_BRANCH_DATA:
      return {
        ...state,
        branchesData: action.data.list,
        currentPage: action.data.currentPage,
        total: action.data.amount,
      };
    case actions.RECEIVE_OVERVIEW_DATA:
      return { ...state, overviewData: action.data };
    case actions.DELETE_BRANCH: {
      const branchName = action.data.branch_name;
      const branchList = state.branchesData.filter((b) => b.name !== branchName);
      return { ...state, branchesData: branchList };
    }
    case actions.RESET_STATE:
      return { ...initialState, pageSize: state.pageSize };
    default:
      return state;
  }
}
